package com.yonyou.pmclouds.project.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.project.entity.ProjectBillStatisticsVO;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.mapper.ProjectStatisticsMapper;

import java.util.UUID;

public class ProjectInitStatisticsProcessor implements SingleProcessor<ProjectVO> {
    private static final String TEMPLATE_PROJECT_ID = "1";
    private ProjectStatisticsMapper mapper;

    public ProjectInitStatisticsProcessor(ProjectStatisticsMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void process(ProjectVO vo, ProjectVO orig) throws BusinessException {
        // gen statistics info
        // 这里使用模板数据
        ProjectBillStatisticsVO[] templates = mapper.queryByProject(TEMPLATE_PROJECT_ID);
        for (ProjectBillStatisticsVO template : templates) {
            template.setPkProject(vo.getPkProject());
            template.setPkTenant(vo.getPkTenant());
            template.setPkStatistics(UUID.randomUUID().toString());
            template.setChangeFlag(UUID.randomUUID().toString());
        }
        // save info
        for (ProjectBillStatisticsVO template : templates) {
            mapper.insert(template);
        }
    }
}
